import requests
import asyncio
import time
from config import LiveConfig


@asyncio.coroutine
def get_data(url):
    data = yield from start_request(url)
    return data


@asyncio.coroutine
def start_request(url):
    yield from asyncio.sleep(0)
    print('start', url)
    r = requests.get(url)
    print('end', url)
    try:
        data = r.json()
    except ValueError:
        data = None
    return data


loop = asyncio.get_event_loop()
tasks = [get_data(_) for _ in LiveConfig.URLS]
start = time.time()
loop.run_until_complete(asyncio.gather(*tasks))
end = time.time()
diff = (end - start) * 1000
print(diff)